package com.example.administrator.tvfoucs;


import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;

import com.owen.focus.AbsFocusBorder;
import com.owen.focus.FocusBorder;
import com.owen.tvgridlayout.SimpleOnItemListener;
import com.owen.tvgridlayout.TvGridLayout;


public class MainActivity extends AppCompatActivity {
    private boolean isXmlMode = true; //表示是否从xml加载布局展示，否则将采用Adapter方式进行布局展示
    protected FocusBorder mFocusBorder;
    private TvGridLayout tvGridLayout;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initFocusBorder(AbsFocusBorder.Mode.TOGETHER);
        tvGridLayout = findViewById(R.id.tv_gridlayout);
        tvGridLayout.setOnItemListener(new SimpleOnItemListener() {
            @Override
            public void onItemPreSelected(TvGridLayout parent, View itemView, int position) {
            }

            @Override
            public void onItemSelected(TvGridLayout parent, View itemView, int position) {
            }

            @Override
            public void onItemClick(final TvGridLayout parent, View itemView, int position) {
                if(position == 0) {
                    startActivity(new Intent(MainActivity.this,TvRecylerviewActivity.class));
                }

            }
        });
        tvGridLayout.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {

            }
        });

    }

    protected void initFocusBorder(AbsFocusBorder.Mode mode) {
        /** 颜色焦点框 */
//        mFocusBorder = new FocusBorder.Builder().asColor()
//                //阴影宽度(方法shadowWidth(18f)也可以设置阴影宽度)
//                .shadowWidth(TypedValue.COMPLEX_UNIT_DIP, 20f)
//                //阴影颜色
//                .shadowColor(Color.parseColor("#3FBB66"))
//                //边框宽度(方法borderWidth(2f)也可以设置边框宽度)
//                .borderWidth(TypedValue.COMPLEX_UNIT_DIP, 3f)
//                //边框颜色
//                .borderColor(Color.parseColor("#00FF00"))
//                //padding值
//                .padding(2f)
//                //动画时长
//                .animDuration(300)
//                //不要闪光效果动画
////                .noShimmer()
//                //闪光颜色
//                .shimmerColor(Color.parseColor("#66FFFFFF"))
//                //闪光动画时长
//                .shimmerDuration(1000)
//                //不要呼吸灯效果
////                .noBreathing()
//                //呼吸灯效果时长
//                .breathingDuration(3000)
//                //边框动画模式
//                .animMode(mode)
//                .build(this);

        /** 图片焦点框 */
        mFocusBorder = new FocusBorder.Builder().asDrawable()
                .borderDrawableRes(R.drawable.focus)
                //标题相关配置
                .titleBackgroundRes(R.drawable.shape_item_title_bg)
                .titleMarginBottomAutoAlignBorder()
                .titleMargin(10, 0, 10, 4)
//                .titlePadding(10)
                .titleWidth(ViewGroup.LayoutParams.MATCH_PARENT)
                .titleTextColor(Color.LTGRAY)
                .titleTextSize(24)
                //边框动画模式
                .animMode(AbsFocusBorder.Mode.NOLL)
                .build(this);

        mFocusBorder.boundGlobalFocusListener(new FocusBorder.OnFocusCallback() {
            @Nullable
            @Override
            public FocusBorder.Options onFocus(View oldFocus, View newFocus) {
                return focus(oldFocus, newFocus);
            }
        });
    }

    protected FocusBorder.Options focus(View oldFocus, View newFocus) {
        if (newFocus instanceof TvGridLayout)
            return null;
        return FocusBorder.OptionsFactory.get(1.2f, 1.2f);
    }
}
